﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Public;
using Model;

namespace Dal
{
    public class FocusSlide
    {
        #region //获取幻灯片列表
        /// <summary>
        /// 获取幻灯片列表
        /// </summary>
        /// <returns>幻灯片列表</returns>
        public DataTable GetFocusList(string strCon) 
        {
            DataTable dt = new DataTable();
            try
            {
                dt = SqlHelper.ExecuteDataTable(DataProtector.DecryptString(strCon), CommandType.StoredProcedure, "SP_FocusSlide_MULTIPLE");
                return dt;
            }
            catch (Exception ex)
            {
                return null;
            }
        }
        #endregion

        #region //根据PKID删除幻灯片——将Valid置为0
        /// <summary>
        /// 根据PKID删除幻灯片——将Valid置为0
        /// </summary>
        /// <param name="pkid">PKID</param>
        /// <returns>1</returns>
        public int DeleteFocusByPKID(int pkid, string strCon) 
        {
            SqlParameter[] pars = { new SqlParameter("@PKID", pkid) };
            try
            {
                return SqlHelper.ExecuteNonQuery(DataProtector.DecryptString(strCon), CommandType.StoredProcedure, "SP_FocusSlide_DELETE", pars);
            }
            catch (Exception ex)
            {
                return 0;
            }
        }
        #endregion

        #region //修改幻灯片内容
        /// <summary>
        /// 修改幻灯片内容
        /// </summary>
        /// <param name="fs">TFocusSlide对象</param>
        /// <returns>1</returns>
        public int UpdateFocusByPKID(Model.FocusSlide fs, string strCon) 
        {
            SqlParameter[] pars = { 
                                    new SqlParameter("@PKID",fs.PKID),  
                                    new SqlParameter("@FocusTitle",fs.FocusTitle),
                                    new SqlParameter("@Summary",fs.Summary),
                                    new SqlParameter("@ImgURL",fs.ImgURL),
                                    new SqlParameter("@LinkURL",fs.LinkURL),
                                    new SqlParameter("@SortBy",fs.SortBy),
                                    new SqlParameter("@StartDate",fs.StartDate),
                                    new SqlParameter("@EndDate",fs.EndDate)
                                  };
            try
            {
                return SqlHelper.ExecuteNonQuery(DataProtector.DecryptString(strCon), CommandType.StoredProcedure, "SP_FocusSlide_UPDATE_PKID", pars);
            }
            catch (Exception ex)
            {
                return 0;
            }
        }
        #endregion

        #region  //根据PKID提取幻灯片数据
        /// <summary>
        /// 根据PKID提取幻灯片数据
        /// </summary>
        /// <param name="pkid">PKID</param>
        /// <returns>TFocusSlid by pkid</returns>
        public DataTable GetFocusByPKID(int pkid, string strCon) 
        {
            SqlParameter[] par = { new SqlParameter("@PKID", pkid) };
            try
            {
                DataTable dt = SqlHelper.ExecuteDataTable(DataProtector.DecryptString(strCon), CommandType.StoredProcedure, "SP_FocusSlide_SINGLE_PKID", par);
                return dt;
            }
            catch (Exception ex)
            {
                return null;
            }
        }
        #endregion

        #region //新增幻灯片
        /// <summary>
        /// 新增幻灯片
        /// </summary>
        /// <param name="fs">FocusSlide实体对象</param>
        /// <returns>1</returns>
        public int AddFocus(Model.FocusSlide fs, string strCon) 
        {
            SqlParameter[] pars = { 
                                    new SqlParameter("@FocusTitle",fs.FocusTitle),
                                    new SqlParameter("@Summary",fs.Summary),
                                    new SqlParameter("@ImgURL",fs.ImgURL),
                                    new SqlParameter("@LinkURL",fs.LinkURL),
                                    new SqlParameter("@SortBy",fs.SortBy),
                                    new SqlParameter("@StartDate",fs.StartDate),
                                    new SqlParameter("@EndDate",fs.EndDate),
                                    new SqlParameter("@CreateDate",fs.CreateDate),
                                    new SqlParameter("@Valid",fs.Valid)
                                  };
            try
            {
                return SqlHelper.ExecuteNonQuery(DataProtector.DecryptString(strCon), CommandType.StoredProcedure, "SP_FocusSlide_INSERT", pars);
            }
            catch (Exception ex)
            {
                return 0;
            }
        }
        #endregion
    }
}
